package modelo;

public class CircuitosDeControle extends Thread {
	private int entrada[] = new int[22];
	private int saida[] = new int[22];
	private int linhaDeControle1, linhaDeControle2, linhaDeControle3;
	private SMailbox canalEntrada = new SMailbox();
	private SMailbox canalControle1 = new SMailbox();
	private SMailbox canalControle2 = new SMailbox();
	private SMailbox canalControle3 = new SMailbox();
	private SMailbox a = new SMailbox();
	private SMailbox b = new SMailbox();
	private SMailbox c = new SMailbox();
	private SMailbox d = new SMailbox();
	private SMailbox e = new SMailbox();
	private SMailbox f = new SMailbox();
	private SMailbox g = new SMailbox();
	private SMailbox h = new SMailbox();
	private SMailbox i = new SMailbox();
	private SMailbox jk = new SMailbox();
	private SMailbox lm = new SMailbox();
	private SMailbox n = new SMailbox();
	private SMailbox o = new SMailbox();
	private SMailbox p = new SMailbox();
	private SMailbox qrstu = new SMailbox();
	private SMailbox v = new SMailbox();
	
	public CircuitosDeControle(SMailbox canalEntrada, SMailbox canalCont1, SMailbox canalCont2, SMailbox canalCont3, SMailbox a, SMailbox b, SMailbox c, SMailbox d, SMailbox e, SMailbox f, SMailbox g, SMailbox h, SMailbox i, SMailbox jk, SMailbox lm, SMailbox n, SMailbox o, SMailbox p, SMailbox qrstu, SMailbox v) {
		this.canalEntrada = canalEntrada;
		this.canalControle1=canalCont1;
		this.canalControle2=canalCont2;
		this.canalControle3=canalCont3;
		this.a=a;
		this.b=b;
		this.c=c;
		this.d=d;
		this.e=e;
		this.f=f;
		this.g=g;
		this.h=h;
		this.i=i;
		this.jk=jk;
		this.lm=lm;
		this.n=n;
		this.o=o;
		this.p=p;
		this.qrstu=qrstu;
		this.v=v;
	}
	
	public void atualizacao(){
		saida=entrada;
	}
	public void run(){
		entrada = (int[]) canalEntrada.receive();
		atualizacao();
		for(int z=0; z<3; z++){
			linhaDeControle1 = (Integer) canalControle1.receive();//t1
			linhaDeControle2 = (Integer) canalControle2.receive();//t2
			linhaDeControle3 = (Integer) canalControle3.receive();//t3
			if(linhaDeControle1==1){
				int aux[]=new int[2];
				aux[0]=saida[9];
				aux[1]=saida[10];
				jk.send(aux);
				aux[0]=saida[11];
				aux[1]=saida[12];
				lm.send(aux);
			}else if(linhaDeControle2==1){
				int aux1[]=new int[5];
				aux1[0]=saida[16];
				aux1[1]=saida[17];
				aux1[2]=saida[18];
				aux1[3]=saida[19];
				aux1[4]=saida[20];
				qrstu.send(aux1);
			}else if(linhaDeControle3==1){
				a.send(saida[0]);
				b.send(saida[1]);
				c.send(saida[2]);
				d.send(saida[3]);
				e.send(saida[4]);
				f.send(saida[5]);
				g.send(saida[6]);
				h.send(saida[7]);
				i.send(saida[8]);
				o.send(saida[14]);
				p.send(saida[15]);
				v.send(saida[21]);
				n.send(saida[13]);
			}
		}
    }
}
